//
//  NSDictionary+WCExtensions.m
//  WabbitCode
//
//  Created by William Towe on 1/10/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import "NSDictionary+WCExtensions.h"
#import "NSSortDescriptor+WCExtensions.h"
#import "WCNewProjectWindowController.h"
#import "WCNewFileWindowController.h"


@implementation NSDictionary (WCExtensions)
- (NSUInteger)unsignedIntegerForKey:(id)key; {
	return [[self objectForKey:key] unsignedIntegerValue];
}
- (NSInteger)integerForKey:(id)key; {
	return [[self objectForKey:key] integerValue];
}
- (NSRect)rectForKey:(id)key; {
	return NSRectFromString([self objectForKey:key]);
}
- (CGFloat)floatForKey:(id)key; {
	return [[self objectForKey:key] floatValue];
}
- (BOOL)boolForKey:(id)key; {
	return [[self objectForKey:key] boolValue];
}
// this should be an NSValue object
- (NSRange)rangeForKey:(id)key; {
	return [[self objectForKey:key] rangeValue];
}

- (BOOL)isValidNewProjectTemplateInfoPlist; {
	if (![self objectForKey:kWCNewProjectTemplateInfoShortDescriptionKey])
		return NO;
	else if (![self objectForKey:kWCNewProjectTemplateInfoLongDescriptionKey])
		return NO;
	else if (![self objectForKey:kWCNewProjectTemplateInfoTargetModelKey])
		return NO;
	else if (![self objectForKey:kWCNewProjectTemplateInfoTargetOutputKey])
		return NO;
	return YES;
}

- (BOOL)isValidNewFileTemplateInfoPlist; {
	if (![self objectForKey:kWCNewFileTemplateInfoShortDescriptionKey])
		return NO;
	else if (![self objectForKey:kWCNewFileTemplateInfoLongDescriptionKey])
		return NO;
	else if (![self objectForKey:kWCNewFileTemplateInfoFileExtensionKey])
		return NO;
	return YES;
}

- (NSSortDescriptor *)sortDescriptorFromDictionary; {
	NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey:[self objectForKey:kDictionaryFromSortDescriptorKeyKey] ascending:([self objectForKey:kDictionaryFromSortDescriptorAscendingKey])?[self boolForKey:kDictionaryFromSortDescriptorAscendingKey]:YES selector:([self objectForKey:kDictionaryFromSortDescriptorSelectorKey])?NSSelectorFromString([self objectForKey:kDictionaryFromSortDescriptorSelectorKey]):@selector(compare:)];

	return [sd autorelease];
}
@end
